package com.itfenxiang.tools.captcha.service.impl;

import cn.hutool.core.lang.UUID;
import com.itfenxiang.tools.captcha.service.SysCaptchaService;
import com.itfenxiang.tools.captcha.vo.SysCaptchaVO;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @description: TODO
 * @author: 墨凡
 * @date: 2024/4/30 12:38
 * @version: 1.0
 */
@Service
@AllArgsConstructor
public class SysCaptchaServiceImpl implements SysCaptchaService {
    @Override
    public SysCaptchaVO generate() {
        // 生成验证码key
        String key = UUID.randomUUID().toString();

        //生成验证码
        SpecCaptcha captcha = new SpecCaptcha(150, 40);
        captcha.setLen(5);
        captcha.setCharType(Captcha.TYPE_DEFAULT);
        String image = captcha.toBase64();

        System.out.println(image);
        //其它动作

        //封装数据
        SysCaptchaVO captchaVO = new SysCaptchaVO();
        captchaVO.setKey(key);
        captchaVO.setImage(image);
        return captchaVO;
    }

    @Override
    public boolean validate(String key, String code) {
        return false;
    }
}
